import { Inject } from '@midwayjs/core';
import { CoolController, BaseController } from '@cool-midway/core';
import { AddressInfoEntity } from '../../entity/info';
import { AddressInfoService } from '../../service/info';
import { UserInfoEntity } from '../../../user/entity/info';

/**
 * 地址信息
 */
@CoolController({
  api: ['add', 'delete', 'update', 'info', 'list', 'page'],
  entity: AddressInfoEntity,
  service: AddressInfoService,
  pageQueryOp: {
    keyWordLikeFields: ['a.consigneeName', 'a.phone'],
    fieldEq: ['a.userId', 'a.isDefault'],
    select: ['a.*', 'b.nickName as consigneeName', 'b.phone as userPhone'],
    join: [
      {
        entity: UserInfoEntity,
        alias: 'b',
        condition: 'a.userId = b.id',
        type: 'leftJoin',
      },
    ],
  },
})
export class AdminAddressInfoController extends BaseController {
  @Inject()
  addressInfoService: AddressInfoService;
}
